 
package com.zdkj.subway.rca.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.admin.api.feign.RemoteSupportService;
import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.in.SwCkStationDailyReportQueryDTO;
import com.zdkj.subway.rca.dto.out.SwCkStationDailyReportAdjustExcelDTO;
import com.zdkj.subway.rca.entity.SwCkStationDailyReportAdjust;
import com.zdkj.subway.rca.mapper.SwCkStationDailyReportAdjustMapper;
import com.zdkj.subway.rca.service.SwCkStationDailyReportAdjustService;
import com.zdkj.subway.rca.service.SwCkStationDailyReportOriginalService;
import com.zdkj.subway.rca.util.LocalDateConverter;
import com.zdkj.subway.rca.util.LocalDateTimeConverter;
import com.zdkj.subway.rca.util.MyBeanUtils;
import com.zdkj.subway.rca.util.MyDateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 报表调账-西安地铁收入日报表
 *
 * @author stw
 * @date 2020-10-30 15:43:30
 */
@Service
public class SwCkStationDailyReportAdjustServiceImpl extends ServiceImpl<SwCkStationDailyReportAdjustMapper, SwCkStationDailyReportAdjust> implements SwCkStationDailyReportAdjustService {
    private static final Logger log = LoggerFactory.getLogger(SwCkStationDailyReportAdjustServiceImpl.class);

    private static final String sumStationCode = "999999";

    @Autowired
    private SwCkStationDailyReportOriginalService swCkStationDailyReportOriginalService;

    @Resource
    private RemoteSupportService remoteSupportService;
   
    @Override
    public List<SwCkStationDailyReportAdjust> listSwCkStationDailyReportAdjust(SwCkStationDailyReportQueryDTO dto) {
        List<SwCkStationDailyReportAdjust> list = this.baseMapper.listSwCkStationDailyReportAdjust(dto);
        return list;
    }

    @Override
    public IPage<List<SwCkStationDailyReportAdjust>> listQuerySwCkStationDailyReportAdjust(Page page, SwCkStationDailyReportQueryDTO dto) {
        return this.baseMapper.listQuerySwCkStationDailyReportAdjust(page,dto);
    }

    @Override
    public void export(SwCkStationDailyReportQueryDTO dtoIn, HttpServletResponse response) {

        List<SwCkStationDailyReportAdjust> list  = this.baseMapper.listSwCkStationDailyReportAdjust(dtoIn);
        List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
		 String lineName = remoteSupportService.getLineNameByCode(dtoIn.getLineCode()).getData();

        List<SwCkStationDailyReportAdjustExcelDTO> records  = new ArrayList<>();
        BigDecimal hundred = new BigDecimal(100);
        for(SwCkStationDailyReportAdjust obj : list) {
            SwCkStationDailyReportAdjustExcelDTO dto = new SwCkStationDailyReportAdjustExcelDTO();

            String stationName = getExportStationName(stationMap,obj.getStationCode(),obj.getLineCode());
            dto.setStationName(stationName);

            dto.setTvmOneTicketCash(new BigDecimal(obj.getTvmOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setTvmOneTicketAlipay(new BigDecimal(obj.getTvmOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setTvmOneTicketWechat(new BigDecimal(obj.getTvmOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setTvmOneTicketBank(new BigDecimal(obj.getTvmOneTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setTvmSubTotal(new BigDecimal(obj.getTvmSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setBomOneTicketCash(new BigDecimal(obj.getBomOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setBomOnePosAmount(new BigDecimal(obj.getBomOnePosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setBomOneTicketAlipay(new BigDecimal(obj.getBomOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

            dto.setBomOneTicketWechat(new BigDecimal(obj.getBomOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setBomSubTotal(new BigDecimal(obj.getBomSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setPrefabricatedTicketAmount(new BigDecimal(obj.getPrefabricatedTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setPrefabricatedTicketPosAmount(new BigDecimal(obj.getPrefabricatedTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setEmergencyTicketAmount(new BigDecimal(obj.getEmergencyTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setTicketCounting(new BigDecimal(obj.getTicketCounting()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setDailyTicketPosAmount(new BigDecimal(obj.getDailyTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setDailyTicketCash(new BigDecimal(obj.getDailyTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setDailyTicketAlipay(new BigDecimal(obj.getDailyTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setDailyTicketCat(new BigDecimal(obj.getDailyTicketCat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

            dto.setDailyTicketWechat(new BigDecimal(obj.getDailyTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setDailySubTotal(new BigDecimal(obj.getDailySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCommemorativeTicketCash(new BigDecimal(obj.getCommemorativeTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setCommemorativeTicketPosAmount(new BigDecimal(obj.getCommemorativeTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCommemorativeTicketAlipay(new BigDecimal(obj.getCommemorativeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCommemorativeTicketWechat(new BigDecimal(obj.getCommemorativeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCommemorativeTicketSubTotal(new BigDecimal(obj.getCommemorativeTicketSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setAppCommemorativeTicket(new BigDecimal(obj.getAppCommemorativeTicket()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

            dto.setCatTicketCash(new BigDecimal(obj.getCatTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setCatTicketPosAmount(new BigDecimal(obj.getCatTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketAlipay(new BigDecimal(obj.getCatTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketWechat(new BigDecimal(obj.getCatTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketItvmCash(new BigDecimal(obj.getCatTicketItvmCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketItvmAlipay(new BigDecimal(obj.getCatTicketItvmAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketItvmWechat(new BigDecimal(obj.getCatTicketItvmWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatTicketItvmBank(new BigDecimal(obj.getCatTicketItvmBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setCatSubTotal(new BigDecimal(obj.getCatSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

            //dto.setCatTicketPayCard(obj.getCatTicketPayCard().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
			dto.setCatTicketPayCard(obj.getCatTicketPayCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setOnlineTicketSales(new BigDecimal(obj.getOnlineTicketSales()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setQrCodeTicketAlipay(new BigDecimal(obj.getQrCodeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setQrCodeTicketWechat(new BigDecimal(obj.getQrCodeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setQrCodeTicketUnionpay(new BigDecimal(obj.getQrCodeTicketUnionpay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setQrCodeTicketApp(new BigDecimal(obj.getQrCodeTicketApp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setQrCodeTicketWechatappDiscount(new BigDecimal(obj.getQrCodeTicketWechatappDiscount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setQrCodeTicketWechatapp(new BigDecimal(obj.getQrCodeTicketWechatapp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setQrCodeSubTotal(new BigDecimal(obj.getQrCodeSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setFaceRecognitionTicketBank(new BigDecimal(obj.getFaceRecognitionTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

			dto.setQrConnectivityAlipay(new BigDecimal(obj.getQrConnectivityAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		    dto.setQrConnectivityWechat(new BigDecimal(obj.getQrConnectivityWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		    dto.setQrConnectivitySubTotal(new BigDecimal(obj.getQrConnectivitySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));


            //dto.setAllOneTrafficCard(obj.getAllOneTrafficCard().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
			dto.setAllOneTrafficCard(obj.getAllOneTrafficCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setStationTicketLongCash(new BigDecimal(obj.getStationTicketLongCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setStationTicketShortCash(new BigDecimal(obj.getStationTicketShortCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setStationCompensation(new BigDecimal(obj.getStationCompensation()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setReleasePettyCash(new BigDecimal(obj.getReleasePettyCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
			dto.setSubTotaPos(new BigDecimal(obj.getSubTotaPos()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            dto.setSettlementAmount(new BigDecimal(obj.getSettlementAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            //dto.setSubTota(obj.getSubTota().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
			dto.setSubTota(obj.getSubTota().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
            records.add(dto);
        }
        InputStream excelTemplateIs = null;
        try {
            response.reset(); // 非常重要
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            final String fileName = URLEncoder.encode("西安中铁票务收入日报表", "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

            // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
            // {} 代表普通变量 {.} 代表是list的变量

            excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkStationDailyReportAdjustExcelTemplate.xlsx");

            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();
            WriteSheet writeSheet = EasyExcel.writerSheet("西安中铁票务收入日报表").build();
            // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
            // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
            // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
            // 如果数据量大 list不是最后一行 参照另一个
            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            excelWriter.fill(records, fillConfig, writeSheet);
			Map<String, Object> map = new HashMap<>();
            //map.put("currDate", DateUtils.format(new Date(),"yyyy年MM月dd日"));
			map.put("currDate",dtoIn.getTradeDate());
			map.put("lineName",lineName);
            excelWriter.fill(map, writeSheet);

            excelWriter.finish();

        } catch (Exception e) {
            e.printStackTrace();
            log.error("导出西安中铁票务收入日报表错误");
        } finally {
            if(excelTemplateIs != null){
                try {
                    excelTemplateIs.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }

            }
        }
    }
    private String getStationName (List<Map<String,String>> stationMap,String stationCode,String lineCode) {
        if(sumStationCode.equals(stationCode)){
            return "合计";
        }
        for (Map<String,String> map : stationMap) {
            if(stationCode.equals(map.get("CODE")) && lineCode.equals(map.get("LINE_CODE"))) {
                return map.get("NAME");
            }
        }
        return "";
    }
   private String getExportStationName (List<Map<String,String>> stationMap,String stationCode,String lineCode) {
        if(sumStationCode.equals(stationCode)){
            return "合计";
        }
        for (Map<String,String> map : stationMap) {
            if(stationCode.equals(map.get("CODE")) && lineCode.equals(map.get("VLINE_CODE"))) {
                return map.get("NAME");
            }
        }
        return "";
    }
	private String getExportLineName (List<Map<String,String>> stationMap,String lineCode) {
           for (Map<String,String> map : stationMap) {
            if(lineCode.equals(map.get("VLINE_CODE"))) {
                return map.get("SECOND_NAME");
            }
        }
        return "";
    }
    /**
     * 根据日期导出调账表
     * @param startDate
     * @param endDate
     * @param lineCodes
	 * @param flag
     * @param response
     */
    @Override
    public void exportDate(String startDate, String endDate, String lineCodes, String flag, HttpServletResponse response) throws ParseException {
        String initLineCodes = lineCodes;
		BigDecimal hundred = new BigDecimal(100);
        //按日期导出，每日的,已根据flag=1的情况下才查询线路合计值中的长安通刷卡消费和交通一卡通金额合计  --涉及每日合计项值
		List<SwCkStationDailyReportAdjust> listDaySingle  = this.baseMapper.listSwCkStationDailyReportAdjustOrDate(startDate,endDate,lineCodes,flag);
        List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
        String[] split = lineCodes.split(",");
        for (int i = 0; i < split.length; i++) {
            if(split[i].length() == 1){
                lineCodes = split[i];
                break;
            }
            lineCodes = split[i];
        }
        String lineName = remoteSupportService.getLineNameByCode(lineCodes).getData();
		//TODO 需要增加按日期导出，车站合计（日期范围内的车站合计）
		List<SwCkStationDailyReportAdjust> listStationTotal  = this.baseMapper.listSwCkStationDailyReportAdjustOrStationTotal(startDate,endDate,initLineCodes,flag);
		//按日期导出，日期合计（开始到结束日期总计）  调用原来的方法
		List<SwCkStationDailyReportAdjust> listDay  = this.baseMapper.listSwCkStationDailyReportAdjustOrStation(startDate,endDate,initLineCodes,flag);
        
		
		Map<Integer, List<SwCkStationDailyReportAdjustExcelDTO>> map = new HashMap<>();
        Map<Integer, LocalDate> mapLocalDate = new HashMap<>();
        if(CollectionUtils.isNotEmpty(listDaySingle)){
            List<String> betweenTwoDate = MyDateUtil.getDatesBetweenTwoDate(startDate, endDate);
            for (int i = 0; i < betweenTwoDate.size(); i++) {
                String  currentDate = betweenTwoDate.get(i);
                LocalDate localCurrentDate = MyDateUtil.StringTurnLocalDate(currentDate);
                int iDate = Integer.parseInt(currentDate.substring(currentDate.length() - 2));//当前日期后两位

                List<SwCkStationDailyReportAdjust> collect = listDaySingle.stream().filter(x -> localCurrentDate.equals(x.getTradeDate())).collect(Collectors.toList());
                List<SwCkStationDailyReportAdjustExcelDTO> records  = new ArrayList<>();
              
                for(SwCkStationDailyReportAdjust obj : collect) {
                    SwCkStationDailyReportAdjustExcelDTO dto = adjustForm(obj, hundred);
                    String stationName = getExportStationName(stationMap,obj.getStationCode(),obj.getLineCode());
                    dto.setStationName(stationName);
                    records.add(dto);
                }
                map.put(iDate,records);
                mapLocalDate.put(iDate,localCurrentDate);
            }
            InputStream excelTemplateIs = null;
            try {response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
				String tmpFileName = "-西安中铁票务收入日报表-按日期导出-";
				if("1".equals(flag)){
				    tmpFileName = "西安中铁票务收入日报表-按财务导出";
				}
                final String fileName = URLEncoder.encode(tmpFileName, "UTF-8");

                response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

                // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                // {} 代表普通变量 {.} 代表是list的变量

                excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkStationDailyReportAdjustOrDateExcelTemplate.xlsx");

                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

                //1. 每日的导出
				for (Map.Entry<Integer, List<SwCkStationDailyReportAdjustExcelDTO>> integerListEntry : map.entrySet()) {
                    Integer key = integerListEntry.getKey();
                    List<SwCkStationDailyReportAdjustExcelDTO> value = integerListEntry.getValue();
                    // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                    // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                    // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                    // 如果数据量大 list不是最后一行 参照另一个
                    WriteSheet writeSheet = EasyExcel.writerSheet(key-1,String.valueOf(key)).build();
                    FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(value, fillConfig, writeSheet);
                    Map<String, Object> mapDate = new HashMap<>();
                    mapDate.put("currDate", mapLocalDate.get(key));
                    mapDate.put("lineName", lineName);
                    excelWriter.fill(mapDate,writeSheet);
                }
				//填补空白的导出
				//TODO 20250307  如果查询的日期范围不是1-31日，需要把开始到结束日期之外的直接补为空的entity
				Map<Integer, List<SwCkStationDailyReportAdjustExcelDTO>> mapSupply = new LinkedHashMap();				
				for(int i=1;i<32;i++){
					if(map!=null && map.containsKey(i)){
						continue;
					}else{
						List<SwCkStationDailyReportAdjustExcelDTO> supplyDto = new ArrayList();
						SwCkStationDailyReportAdjustExcelDTO dto = new SwCkStationDailyReportAdjustExcelDTO();
						supplyDto.add(dto);
						mapSupply.put(i,supplyDto);
					}
				}
				for (Map.Entry<Integer, List<SwCkStationDailyReportAdjustExcelDTO>> suppIntegerListEntry : mapSupply.entrySet()) {
                    Integer key = suppIntegerListEntry.getKey();
                    List<SwCkStationDailyReportAdjustExcelDTO> value = suppIntegerListEntry.getValue();
                   
                    WriteSheet writeSheet = EasyExcel.writerSheet(key-1,String.valueOf(key)).build();
                    FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(value, fillConfig, writeSheet);
                    Map<String, Object> mapDate = new HashMap<>();
                    //mapDate.put("currDate", mapLocalDate.get(key));//日期需要重新组织
                    mapDate.put("lineName", lineName);
                    excelWriter.fill(mapDate,writeSheet);
                }
				//填补空白的导出 结束
				
                //车站和日期合计，填写日期
				Map<String, Object> mapOther = new HashMap<>();
                mapOther.put("lineName",lineName);
				mapOther.put("startDate",startDate);
				mapOther.put("endDate",endDate);

                //2. 车站合计
                if(CollectionUtil.isNotEmpty(listStationTotal)){
                    List<SwCkStationDailyReportAdjustExcelDTO> recordsStationTotal  = new ArrayList<>();
                    for(SwCkStationDailyReportAdjust obj : listStationTotal) {
                        SwCkStationDailyReportAdjustExcelDTO dto = adjustForm(obj, hundred);					
                        String stationName = getExportStationName(stationMap,obj.getStationCode(),obj.getLineCode());						
                        dto.setStationName(stationName);
                        recordsStationTotal.add(dto);
                    }
                    //必须加上sheetNo,否则会追加
                    WriteSheet writeSheetStationAll = EasyExcel.writerSheet(31,"车站合计").build();
                    FillConfig fillConfigStationAll = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(recordsStationTotal, fillConfigStationAll, writeSheetStationAll);

                    excelWriter.fill(mapOther, writeSheetStationAll);
                }

				//3. 日期合计
				if(CollectionUtil.isNotEmpty(listDay)){
                    List<SwCkStationDailyReportAdjustExcelDTO> recordsDay  = new ArrayList<>();
					BigDecimal CatTicketPayCardSum = new BigDecimal("0");
					BigDecimal AllOneTrafficCardSum = new BigDecimal("0");
                    for(SwCkStationDailyReportAdjust obj : listDay) {
                        SwCkStationDailyReportAdjustExcelDTO dto = adjustForm(obj, hundred);
                        dto.setTradeDateToString(obj.getTradeDateToString());
						
						if(!"合计".equals(obj.getTradeDateToString())){						 
						  CatTicketPayCardSum = CatTicketPayCardSum.add(dto.getCatTicketPayCard());
                          AllOneTrafficCardSum = AllOneTrafficCardSum.add(dto.getAllOneTrafficCard());  
						 
						}else{						  
						  dto.setCatTicketPayCard(CatTicketPayCardSum);	
						  dto.setAllOneTrafficCard(AllOneTrafficCardSum);	
						    //重新计算待清分的值
						    BigDecimal subTotalSum = new BigDecimal("0");
							subTotalSum = obj.getSubTota();
							subTotalSum = subTotalSum.subtract(obj.getCatTicketPayCard()).subtract(obj.getAllOneTrafficCard());
							subTotalSum = subTotalSum.divide(hundred,2,BigDecimal.ROUND_HALF_UP);
							subTotalSum = subTotalSum.add(CatTicketPayCardSum).add(AllOneTrafficCardSum);
							dto.setSubTota(subTotalSum.divide(new BigDecimal("1"),2,BigDecimal.ROUND_HALF_UP));
						}
                        recordsDay.add(dto);
                    }

                    //必须加上sheetNo,否则会追加
                    WriteSheet writeSheetDay = EasyExcel.writerSheet(32,"日期合计").build();
                    FillConfig fillConfigDay = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(recordsDay, fillConfigDay, writeSheetDay);
                    excelWriter.fill(mapOther, writeSheetDay);
                }

				//最后完成
                excelWriter.finish();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("导出西安中铁票务收入日报表错误");
            } finally {
                if(excelTemplateIs != null){
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }

                }
            }
        }
    }

    /**
     * 根据线路导出调账表
     * @param startDate
     * @param endDate
     * @param lineCodes  可以多选
     * @param response
     */
    @Override
    public void exportStation(String startDate, String endDate, String lineCodes, String flag,HttpServletResponse response) throws ParseException {      
		List<SwCkStationDailyReportAdjust> list  = this.baseMapper.listSwCkStationDailyReportAdjustOrStation(startDate,endDate,lineCodes,flag);
        String[] split = lineCodes.split(",");
        for (int i = 0; i < split.length; i++) {
            if(split[i].length() == 1){
                lineCodes = split[i];
                break;
            }
            lineCodes = split[i];
        }
        String lineName = remoteSupportService.getLineNameByCode(lineCodes).getData();
        if(CollectionUtils.isNotEmpty(list)){

            List<SwCkStationDailyReportAdjustExcelDTO> records  = new ArrayList<>();
            BigDecimal hundred = new BigDecimal(100);
            for(SwCkStationDailyReportAdjust obj : list) {
                SwCkStationDailyReportAdjustExcelDTO dto = adjustForm(obj, hundred);
                dto.setTradeDateToString(obj.getTradeDateToString());
                records.add(dto);
            }
            InputStream excelTemplateIs = null;
            try {response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                final String fileName = URLEncoder.encode("-西安中铁票务收入日报表-按线路导出-", "UTF-8");
                response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

                // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                // {} 代表普通变量 {.} 代表是list的变量

                excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkStationDailyReportAdjustOrStationExcelTemplate.xlsx");

                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();
                WriteSheet writeSheet = EasyExcel.writerSheet("西安中铁票务收入日报表").build();
                // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                // 如果数据量大 list不是最后一行 参照另一个
                FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                excelWriter.fill(records, fillConfig, writeSheet);
                Map<String, Object> map = new HashMap<>();
                map.put("lineName",lineName);
                excelWriter.fill(map, writeSheet);

                excelWriter.finish();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("导出西安中铁票务收入日报表错误");
            } finally {
                if(excelTemplateIs != null){
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }

                }
            }
        }
    }

    private SwCkStationDailyReportAdjustExcelDTO adjustForm(SwCkStationDailyReportAdjust obj, BigDecimal hundred) {
        SwCkStationDailyReportAdjustExcelDTO dto = new SwCkStationDailyReportAdjustExcelDTO();
        dto.setTradeDateToString(obj.getTradeDateToString());
		//小计放到最前面处理,先减去原始的交通卡和刷卡，再重新计算2位数的合计
		BigDecimal CatTicketPayCardSum = new BigDecimal("0");
		BigDecimal AllOneTrafficCardSum = new BigDecimal("0");
		BigDecimal subTotalSum = new BigDecimal("0");
		subTotalSum = obj.getSubTota();
        CatTicketPayCardSum = obj.getCatTicketPayCard();
        AllOneTrafficCardSum = obj.getAllOneTrafficCard();
        subTotalSum = subTotalSum.subtract(CatTicketPayCardSum).subtract(AllOneTrafficCardSum);
		subTotalSum = subTotalSum.divide(hundred,2,BigDecimal.ROUND_HALF_UP);
        subTotalSum = subTotalSum.add(obj.getCatTicketPayCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP)).add(obj.getAllOneTrafficCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setSubTota(subTotalSum.divide(new BigDecimal("1"),2,BigDecimal.ROUND_HALF_UP));

        dto.setTvmOneTicketCash(new BigDecimal(obj.getTvmOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setTvmOneTicketAlipay(new BigDecimal(obj.getTvmOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setTvmOneTicketWechat(new BigDecimal(obj.getTvmOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setTvmOneTicketBank(new BigDecimal(obj.getTvmOneTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setTvmSubTotal(new BigDecimal(obj.getTvmSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setBomOneTicketCash(new BigDecimal(obj.getBomOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setBomOnePosAmount(new BigDecimal(obj.getBomOnePosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setBomOneTicketAlipay(new BigDecimal(obj.getBomOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

        dto.setBomOneTicketWechat(new BigDecimal(obj.getBomOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setBomSubTotal(new BigDecimal(obj.getBomSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setPrefabricatedTicketAmount(new BigDecimal(obj.getPrefabricatedTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setPrefabricatedTicketPosAmount(new BigDecimal(obj.getPrefabricatedTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        
		dto.setEmergencyTicketAmount(new BigDecimal(obj.getEmergencyTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setTicketCounting(new BigDecimal(obj.getTicketCounting()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        
		dto.setDailyTicketCash(new BigDecimal(obj.getDailyTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setDailyTicketPosAmount(new BigDecimal(obj.getDailyTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setDailyTicketAlipay(new BigDecimal(obj.getDailyTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setDailyTicketWechat(new BigDecimal(obj.getDailyTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setDailyTicketCat(new BigDecimal(obj.getDailyTicketCat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setDailySubTotal(new BigDecimal(obj.getDailySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

        dto.setCommemorativeTicketCash(new BigDecimal(obj.getCommemorativeTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setCommemorativeTicketPosAmount(new BigDecimal(obj.getCommemorativeTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCommemorativeTicketAlipay(new BigDecimal(obj.getCommemorativeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCommemorativeTicketWechat(new BigDecimal(obj.getCommemorativeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCommemorativeTicketSubTotal(new BigDecimal(obj.getCommemorativeTicketSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setAppCommemorativeTicket(new BigDecimal(obj.getAppCommemorativeTicket()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

        dto.setCatTicketCash(new BigDecimal(obj.getCatTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setCatTicketPosAmount(new BigDecimal(obj.getCatTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketAlipay(new BigDecimal(obj.getCatTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketWechat(new BigDecimal(obj.getCatTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketItvmCash(new BigDecimal(obj.getCatTicketItvmCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketItvmAlipay(new BigDecimal(obj.getCatTicketItvmAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketItvmWechat(new BigDecimal(obj.getCatTicketItvmWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatTicketItvmBank(new BigDecimal(obj.getCatTicketItvmBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setCatSubTotal(new BigDecimal(obj.getCatSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

        //dto.setCatTicketPayCard(obj.getCatTicketPayCard().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
		dto.setCatTicketPayCard(obj.getCatTicketPayCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setOnlineTicketSales(new BigDecimal(obj.getOnlineTicketSales()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setQrCodeTicketAlipay(new BigDecimal(obj.getQrCodeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setQrCodeTicketWechat(new BigDecimal(obj.getQrCodeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setQrCodeTicketUnionpay(new BigDecimal(obj.getQrCodeTicketUnionpay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setQrCodeTicketApp(new BigDecimal(obj.getQrCodeTicketApp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setQrCodeTicketWechatappDiscount(new BigDecimal(obj.getQrCodeTicketWechatappDiscount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setQrCodeTicketWechatapp(new BigDecimal(obj.getQrCodeTicketWechatapp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setQrCodeSubTotal(new BigDecimal(obj.getQrCodeSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setFaceRecognitionTicketBank(new BigDecimal(obj.getFaceRecognitionTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

		dto.setQrConnectivityAlipay(new BigDecimal(obj.getQrConnectivityAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setQrConnectivityWechat(new BigDecimal(obj.getQrConnectivityWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setQrConnectivitySubTotal(new BigDecimal(obj.getQrConnectivitySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

        //dto.setAllOneTrafficCard(obj.getAllOneTrafficCard().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
		dto.setAllOneTrafficCard(obj.getAllOneTrafficCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setStationTicketLongCash(new BigDecimal(obj.getStationTicketLongCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setStationTicketShortCash(new BigDecimal(obj.getStationTicketShortCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setStationCompensation(new BigDecimal(obj.getStationCompensation()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setReleasePettyCash(new BigDecimal(obj.getReleasePettyCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        dto.setSettlementAmount(new BigDecimal(obj.getSettlementAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
		dto.setSubTotaPos(new BigDecimal(obj.getSubTotaPos()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
        //dto.setSubTota(obj.getSubTota().divide(hundred,4,BigDecimal.ROUND_HALF_UP));
		//dto.setSubTota(obj.getSubTota().divide(hundred,2,BigDecimal.ROUND_HALF_UP)); 移到最开始
        return dto;
    }
	@Override
    public Boolean saveBatchWithExcel(final File file) throws Exception{

		PigxUser user = SecurityUtils.getUser();
	    ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file);
        List<ReadSheet> sheets = excelReaderBuilder.build().excelExecutor().sheetList();
		String lineName = file.getName().split("\\.")[0];  //文件名必须为线路名称 ，如 1号线    14号线东段  1号线二期  5号线二期
		List<Map<String,String>> lineMap = this.baseMapper.selectLineMap();
        List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
		//考虑一期二期
		String lineCode = getLineCode(lineMap,lineName);	
        
		List<SwCkStationDailyReportAdjust> listDb = new ArrayList<>();

        List<SwCkStationDailyReportAdjust> listOld = new ArrayList<>();

        for(int n = 0; n < sheets.size(); n++) {
            String tradeDate = sheets.get(n).getSheetName();
			if(!parseDate(tradeDate)){//日期不合法,每个sheet名称必须命名为 2021-09-01
			  continue;
			}
            //只有是每个月的最后一天，从导入的对账确认表内获取对应的金额，放到2号线北苑车站和合计项内。
            LocalDate localDate = MyDateUtil.StringTurnLocalDate(tradeDate);
            LocalDate lastDayOfMonth = localDate.with(TemporalAdjusters.lastDayOfMonth());
            boolean isLastDay = Period.between(localDate, lastDayOfMonth).getDays() == 0;// true表示是最后一天，false表示不是最后一天

            List<Map<Integer, String>> listMap = excelReaderBuilder.sheet(n).headRowNumber(4).doReadSync();
            if (CollectionUtil.isNotEmpty(listMap)) {
                //todo 需要根据 tradedate,linecode 两个值查找调整表，如果存在将其原来的删除
                LambdaQueryWrapper<SwCkStationDailyReportAdjust> wrapper =
                        Wrappers.<SwCkStationDailyReportAdjust>lambdaQuery()
                        .eq(SwCkStationDailyReportAdjust::getTradeDate, tradeDate)
                        .eq(SwCkStationDailyReportAdjust::getLineCode, lineCode);
                List<SwCkStationDailyReportAdjust> oneList = this.list(wrapper);
                if(CollectionUtil.isNotEmpty(oneList)){
                    listOld.addAll(oneList);
                }
                for (int m = 1; m < listMap.size(); m++) {

                    Map<Integer, String> data = listMap.get(m);
                    // 返回每条数据的键值对 表示所在的列 和所在列的值
                    log.info("读取到数据:{}", JSON.toJSONString(data));
                    if(data.get(0) == null){
                        continue;
                    }
					SwCkStationDailyReportAdjust obj = new SwCkStationDailyReportAdjust();
					
					String stationName = data.get(0);
					String stationCode = "";
					if(stationName.equals("合计")){
						stationCode = sumStationCode;
					}else{
					   //考虑一期二期
					   stationCode = getStationCode(stationMap,stationName,lineCode);
					}
					if("".equals(stationCode)){
					    continue;
                    }
                    obj.setTradeDate(MyDateUtil.StringTurnLocalDate(tradeDate));
                    obj.setLineCode(lineCode);
                    obj.setStationCode(stationCode);
                    obj.setSettleBeginTime(obj.getTradeDate());
                    obj.setSettleEndTime(obj.getTradeDate());
					obj.setTvmOneTicketCash(getImportLongValue(data.get(1)));
					obj.setTvmOneTicketAlipay(getImportLongValue(data.get(2)));
					obj.setTvmOneTicketWechat(getImportLongValue(data.get(3)));
					obj.setTvmOneTicketBank(getImportLongValue(data.get(4)));
					obj.setTvmSubTotal(getImportLongValue(data.get(5)));

					obj.setBomOneTicketCash(getImportLongValue(data.get(6)));
					obj.setBomOneTicketAlipay(getImportLongValue(data.get(7)));
					obj.setBomOneTicketWechat(getImportLongValue(data.get(8)));
					obj.setBomSubTotal(getImportLongValue(data.get(9)));
				   
					obj.setPrefabricatedTicketAmount(getImportLongValue(data.get(10)));
					obj.setEmergencyTicketAmount(getImportLongValue(data.get(11)));
					obj.setTicketCounting(getImportLongValue(data.get(12)));
					
					obj.setDailyTicketCash(getImportLongValue(data.get(13)));
					obj.setDailyTicketAlipay(getImportLongValue(data.get(14)));
					obj.setDailyTicketWechat(getImportLongValue(data.get(15)));

                    if("2".equals(lineCode) && isLastDay){
                        obj.setDailyTicketCat(getImportLongValue(data.get(16)));
                        obj.setDailySubTotal(getImportLongValue(data.get(17)));
                        obj.setCommemorativeTicketCash(getImportLongValue(data.get(18)));
                        obj.setCommemorativeTicketAlipay(getImportLongValue(data.get(19)));
                        obj.setCommemorativeTicketWechat(getImportLongValue(data.get(20)));
                        obj.setCommemorativeTicketSubTotal(getImportLongValue(data.get(21)));

                        obj.setAppCommemorativeTicket(getImportLongValue(data.get(22)));

                        obj.setCatTicketCash(getImportLongValue(data.get(23)));
                        obj.setCatTicketAlipay(getImportLongValue(data.get(24)));
                        obj.setCatTicketWechat(getImportLongValue(data.get(25)));

                        obj.setCatTicketItvmCash(getImportLongValue("0"));//模板无此值
                        obj.setCatTicketItvmAlipay(getImportLongValue(data.get(26)));
                        obj.setCatTicketItvmWechat(getImportLongValue(data.get(27)));
                        obj.setCatTicketItvmBank(getImportLongValue("0"));//模板无此值
                        obj.setCatSubTotal(getImportLongValue(data.get(29)));

                        //长安通刷卡消费，交通一卡通，总计的收入小计会加上该两项值
                        obj.setCatTicketPayCard(getDecimalValue(data.get(30)));                  


                        //obj.setOnlineTicketSales(getImportLongValue(data.get(31)));
                        obj.setOnlineTicketSales(getImportLongValue("0"));
                        obj.setQrCodeTicketAlipay(getImportLongValue(data.get(31)));
                        obj.setQrCodeTicketWechat(getImportLongValue(data.get(32)));
                        obj.setQrCodeTicketUnionpay(getImportLongValue(data.get(33)));

						obj.setQrCodeTicketApp(getImportLongValue(data.get(34)));
						//20230130新增两列
						obj.setQrCodeTicketWechatappDiscount(getImportLongValue(data.get(35)));
						obj.setQrCodeTicketWechatapp(getImportLongValue(data.get(36)));
						//
                        
						obj.setQrCodeSubTotal(getImportLongValue(data.get(37)));

                        obj.setFaceRecognitionTicketBank(getImportLongValue(data.get(38)));

                        obj.setQrConnectivityAlipay(getImportLongValue(data.get(39)));
                        obj.setQrConnectivityWechat(getImportLongValue(data.get(40)));
                        obj.setQrConnectivitySubTotal(getImportLongValue(data.get(41)));
						obj.setAllOneTrafficCard(getDecimalValue(data.get(42)));

                        obj.setStationTicketLongCash(getImportLongValue(data.get(43)));
                        obj.setStationTicketShortCash(getImportLongValue(data.get(44)));
                        obj.setStationCompensation(getImportLongValue(data.get(45)));

                        obj.setReleasePettyCash(getImportLongValue(data.get(46)));
                        obj.setSettlementAmount(getImportLongValue(data.get(47)));
                        obj.setSubTota(getDecimalValue(data.get(48)));

                        
						/*
						obj.setQrCodeSubTotal(getLongValue(data.get(35)));

                        obj.setFaceRecognitionTicketBank(getLongValue(data.get(36)));

                        obj.setQrConnectivityAlipay(getLongValue(data.get(37)));
                        obj.setQrConnectivityWechat(getLongValue(data.get(38)));
                        obj.setQrConnectivitySubTotal(getLongValue(data.get(39)));
						obj.setAllOneTrafficCard(getDecimalValue(data.get(40)));

                        obj.setStationTicketLongCash(getLongValue(data.get(41)));
                        obj.setStationTicketShortCash(getLongValue(data.get(42)));
                        obj.setStationCompensation(getLongValue(data.get(43)));

                        obj.setReleasePettyCash(getLongValue(data.get(44)));
                        obj.setSettlementAmount(getLongValue(data.get(45)));
                        obj.setSubTota(getDecimalValue(data.get(46)));
						*/
                    }else {
                        obj.setDailySubTotal(getImportLongValue(data.get(16)));
                        obj.setCommemorativeTicketCash(getImportLongValue(data.get(17)));
                        obj.setCommemorativeTicketAlipay(getImportLongValue(data.get(18)));
                        obj.setCommemorativeTicketWechat(getImportLongValue(data.get(19)));
                        obj.setCommemorativeTicketSubTotal(getImportLongValue(data.get(20)));

                        obj.setAppCommemorativeTicket(getImportLongValue(data.get(21)));

                        obj.setCatTicketCash(getImportLongValue(data.get(22)));
                        obj.setCatTicketAlipay(getImportLongValue(data.get(23)));
                        obj.setCatTicketWechat(getImportLongValue(data.get(24)));

                        obj.setCatTicketItvmCash(getImportLongValue("0"));//模板无此值
                        obj.setCatTicketItvmAlipay(getImportLongValue(data.get(25)));
                        obj.setCatTicketItvmWechat(getImportLongValue(data.get(26)));
                        obj.setCatTicketItvmBank(getImportLongValue("0"));//模板无此值
                        obj.setCatSubTotal(getImportLongValue(data.get(28)));

                        //长安通刷卡消费，交通一卡通，总计的收入小计会加上该两项值
                        obj.setCatTicketPayCard(getDecimalValue(data.get(29)));
                        obj.setAllOneTrafficCard(getDecimalValue(data.get(40)));


                        obj.setOnlineTicketSales(getImportLongValue("0"));//网络消费去掉  20240204
                        obj.setQrCodeTicketAlipay(getImportLongValue(data.get(30)));
                        obj.setQrCodeTicketWechat(getImportLongValue(data.get(31)));
                        obj.setQrCodeTicketUnionpay(getImportLongValue(data.get(32)));
						//20230130新增两列
						obj.setQrCodeTicketWechatappDiscount(getImportLongValue(data.get(33)));
						obj.setQrCodeTicketWechatapp(getImportLongValue(data.get(34)));
						//
                        obj.setQrCodeSubTotal(getImportLongValue(data.get(35)));

                        obj.setFaceRecognitionTicketBank(getImportLongValue(data.get(36)));

                        obj.setQrConnectivityAlipay(getImportLongValue(data.get(37)));
                        obj.setQrConnectivityWechat(getImportLongValue(data.get(38)));
                        obj.setQrConnectivitySubTotal(getImportLongValue(data.get(39)));

                        obj.setStationTicketLongCash(getImportLongValue(data.get(41)));
                        obj.setStationTicketShortCash(getImportLongValue(data.get(42)));
                        obj.setStationCompensation(getImportLongValue(data.get(43)));

                        obj.setReleasePettyCash(getImportLongValue(data.get(44)));
                        obj.setSettlementAmount(getImportLongValue(data.get(45)));
                        obj.setSubTota(getDecimalValue(data.get(46)));
                    }

					obj.setDeptId(user.getDeptId());
                    obj.setCreatorId(user.getId());
                    obj.setCreatorName(user.getNikeName());
                    obj.setCreateTime(LocalDateTime.now());
                    obj.setConfirmStatus("0");//确认状态默认0
					listDb.add(obj);
					
                }
            }
        }
        MultipartFileToFile.delteTempFile(file);

        //todo 需要根据 tradedate,linecode 两个值查找调整表，如果存在将其原来的删除，然后插入
        if(CollectionUtil.isNotEmpty(listOld)){
            List<Long> longList = listOld.stream().map(SwCkStationDailyReportAdjust::getId).collect(Collectors.toList());
            this.removeByIds(longList);
        }
        if(!listDb.isEmpty()) {          
			return  this.saveBatch(listDb);
        }

        return false;
	}
	 /**
     * 产生日报表调账表  ---此方法不再使用
     * @return
     */
    @Override
    public Boolean generate(String startDate,String endDate) throws Exception {
        /*
		List<Map<String,String>> stationObjList = this.baseMapper.selectStationMap();
        List<String> listDate = MyDateUtil.getDatesBetweenTwoDate(startDate,endDate);

        //根据日期范围获取站点结算周期list
        List<Map<String,String>> stationSettleCycleList = swCkStationDailyReportOriginalService.getStationSettleCycleList(startDate,endDate);

        List<SwCkStationDailyReportAdjust> insertList = new ArrayList<>();

        PigxUser user = SecurityUtils.getUser();
        for (Map<String,String> stationMap : stationObjList){
            String lineCode = stationMap.get("LINE_CODE");
            String stationCode = stationMap.get("CODE");
            //循环时间段内每一天
            for(String settleDate : listDate) {
                Map<String,String> stationSettleCycleMap = findStationSettleCycleMap(lineCode,stationCode,settleDate,stationSettleCycleList);
                if(stationSettleCycleMap != null) {

                    String beginDate = stationSettleCycleMap.get("beginDate");

                    LocalDate settleBeginTime = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")) ;
                    LocalDate settleEndTime = LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")) ;

                    SwCkStationDailyReportAdjust insertObj = new SwCkStationDailyReportAdjust();
                    insertObj.setTradeDate(settleEndTime);
                    insertObj.setLineCode(lineCode);
                    insertObj.setStationCode(stationCode);

                    //假如已经存在数据则返回
                    if (this.count(Wrappers.query(insertObj)) > 0){
                        continue;
                    }

                    insertObj.setSettleBeginTime(settleBeginTime);
                    insertObj.setSettleEndTime(settleEndTime);

                    insertObj.setDeptId(user.getDeptId());
                    insertObj.setCreatorId(user.getId());
                    insertObj.setCreatorName(user.getNikeName());

                    //TVM现金单程票金额
                    Map<String,Long> tvmOneTicketCashMap = this.baseMapper.getTvmOneTicketCash(insertObj);
                    insertObj.setTvmOneTicketCash(tvmOneTicketCashMap.get("tvmOneTicketCash"));

                    //TVM支付宝单程票金额
                    Map<String,Long> tvmOneTicketAlipayMap = this.baseMapper.getTvmOneTicketAlipay(insertObj);
                    insertObj.setTvmOneTicketAlipay(tvmOneTicketAlipayMap.get("tvmOneTicketAlipay"));

                    //TVM微信单程票金额
                    Map<String,Long> tvmOneTicketWechatMap = this.baseMapper.getTvmOneTicketWechat(insertObj);
                    insertObj.setTvmOneTicketWechat(tvmOneTicketWechatMap.get("tvmOneTicketWechat"));

                    //TVM银行单程票金额
                    Map<String,Long> tvmOneTicketBankMap = this.baseMapper.getTvmOneTicketBank(insertObj);
                    insertObj.setTvmOneTicketBank(tvmOneTicketBankMap.get("tvmOneTicketBank"));

                    //TVM发售小计
                    insertObj.setTvmSubTotal(insertObj.getTvmOneTicketCash() + insertObj.getTvmOneTicketAlipay() + insertObj.getTvmOneTicketWechat() + insertObj.getTvmOneTicketBank());

                    //BOM现金单程票金额
                    Map<String,Long> bomOneTicketCashMap = this.baseMapper.getBomOneTicketCash(insertObj);
                    insertObj.setBomOneTicketCash(bomOneTicketCashMap.get("bomOneTicketCash"));


                    //BOM支付宝单程票金额
                    Map<String,Long> bomOneTicketAlipayMap = this.baseMapper.getBomOneTicketAlipay(insertObj);
                    insertObj.setBomOneTicketAlipay(bomOneTicketAlipayMap.get("bomOneTicketAlipay"));
                    //BOM微信单程票金额
                    Map<String,Long> bomOneTicketWechatMap = this.baseMapper.getBomOneTicketWechat(insertObj);
                    insertObj.setBomOneTicketWechat(bomOneTicketWechatMap.get("bomOneTicketWechat"));
                    //BOM票款小计
                    insertObj.setBomSubTotal(insertObj.getBomOneTicketCash() + insertObj.getBomOneTicketAlipay() + insertObj.getBomOneTicketWechat());

                    //预制票金额
                    Map<String,Long> prefabricatedTicketAmountMap = this.baseMapper.getPrefabricatedTicketAmount(insertObj);
                    insertObj.setPrefabricatedTicketAmount(prefabricatedTicketAmountMap.get("prefabricatedTicketAmount"));

                    //应急票金额
                    Map<String,Long> emergencyTicketAmount = this.baseMapper.getEmergencyTicketAmount(insertObj);
                    insertObj.setEmergencyTicketAmount(emergencyTicketAmount.get("emergencyTicketAmount"));

                    //计次票金额
                    Map<String,Long> ticketCountingMap = this.baseMapper.getTicketCounting(insertObj);
                    insertObj.setTicketCounting(ticketCountingMap.get("ticketCounting"));

                    //日票现金其他车票金额
                    Map<String,Long> dailyTicketCashMap = this.baseMapper.getDailyTicketCash(insertObj);
                    insertObj.setDailyTicketCash(dailyTicketCashMap.get("dailyTicketCash"));

                    Map<String,Long> dailyTicketAlipayMap = this.baseMapper.getDailyTicketAlipay(insertObj);
                    //日票支付宝其他车票金额
                    insertObj.setDailyTicketAlipay(dailyTicketAlipayMap.get("dailyTicketAlipay"));

                    Map<String,Long> dailyTicketWechatMap = this.baseMapper.getDailyTicketWechat(insertObj);
                    //日票微信其他票种金额
                    insertObj.setDailyTicketWechat(dailyTicketWechatMap.get("dailyTicketWechat"));

                    //日票其他车票小计
                    insertObj.setDailySubTotal(insertObj.getDailyTicketCash() + insertObj.getDailyTicketAlipay() + insertObj.getDailyTicketWechat());

                    //纪念票现金其他车票金额
                    Map<String,Long> commemorativeTicketCashMap = this.baseMapper.getCommemorativeTicketCash(insertObj);
                    insertObj.setCommemorativeTicketCash(commemorativeTicketCashMap.get("commemorativeTicketCash"));

                    Map<String,Long> commemorativeTicketAlipayMap = this.baseMapper.getCommemorativeTicketAlipay(insertObj);
                    //纪念票支付宝其他车票金额
                    insertObj.setCommemorativeTicketAlipay(commemorativeTicketAlipayMap.get("commemorativeTicketAlipay"));

                    Map<String,Long> commemorativeTicketWechatMap = this.baseMapper.getCommemorativeTicketWechat(insertObj);
                    //纪念票微信其他车票金额
                    insertObj.setCommemorativeTicketWechat(commemorativeTicketWechatMap.get("commemorativeTicketWechat"));

                    //纪念票小计
                    insertObj.setCommemorativeTicketSubTotal(insertObj.getCommemorativeTicketCash() + insertObj.getCommemorativeTicketAlipay() + insertObj. getCommemorativeTicketWechat());

                    //APP纪念票金额
                    Map<String,Long> appCommemorativeTicketMap = this.baseMapper.getAppCommemorativeTicket(insertObj);
                    insertObj.setAppCommemorativeTicket(appCommemorativeTicketMap.get("appCommemorativeTicket"));

                    //长安通现金充值金额
                    Map<String,Long> catTicketCashMap = this.baseMapper.getCatTicketCash(insertObj);
                    insertObj.setCatTicketCash(catTicketCashMap.get("catTicketCash"));

                    //长安通支付宝充值金额
                    Map<String,Long> catTicketAlipayMap = this.baseMapper.getCatTicketAlipay(insertObj);
                    insertObj.setCatTicketAlipay(catTicketAlipayMap.get("catTicketAlipay"));

                    //长安通微信充值金额
                    Map<String,Long> catTicketWechatMap = this.baseMapper.getCatTicketWechat(insertObj);
                    insertObj.setCatTicketWechat(catTicketWechatMap.get("catTicketWechat"));

                    //长安通ITVM现金充值金额
                    Map<String,Long> catTicketItvmCashMap = this.baseMapper.getCatTicketItvmCash(insertObj);
                    insertObj.setCatTicketItvmCash(catTicketItvmCashMap.get("catTicketItvmCash"));

                    //长安通ITVM支付宝充值金额
                    Map<String,Long> catTicketItvmAlipayMap = this.baseMapper.getCatTicketItvmAlipay(insertObj);
                    insertObj.setCatTicketItvmAlipay(catTicketItvmAlipayMap.get("catTicketItvmAlipay"));

                    //长安通ITVM微信充值金额
                    Map<String,Long> catTicketItvmWechatMap = this.baseMapper.getCatTicketItvmWechat(insertObj);
                    insertObj.setCatTicketItvmWechat(catTicketItvmWechatMap.get("catTicketItvmWechat"));

                    //长安通Itvm建行充值金额
                    Map<String,Long> catTicketItvmBankMap = this.baseMapper.getCatTicketItvmBank(insertObj);
                    insertObj.setCatTicketItvmBank(catTicketItvmBankMap.get("catTicketItvmBank"));

                    //长安通小计
                    insertObj.setCatSubTotal(insertObj.getCatTicketCash() + insertObj.getCatTicketAlipay() + insertObj.getCatTicketWechat()
                            + insertObj.getCatTicketItvmCash()  + insertObj.getCatTicketItvmAlipay() + insertObj.getCatTicketItvmWechat() + insertObj.getCatTicketItvmBank());

                    //长安通刷卡消费
                    insertObj.setCatTicketPayCard(0L);

                    //网络售票
                    Map<String,Long> onlineTicketSalesMap = this.baseMapper.getOnlineTicketSales(insertObj);
                    insertObj.setOnlineTicketSales(onlineTicketSalesMap.get("onlineTicketSales"));

                    Map<String,Long> qrCodeTicketMap = this.baseMapper.getQrCodeTicket(insertObj);
                    //二维码支付宝金额
                    insertObj.setQrCodeTicketAlipay(qrCodeTicketMap.get("qrCodeTicketAlipay"));
                    //二维码微信金额
                    insertObj.setQrCodeTicketWechat(qrCodeTicketMap.get("qrCodeTicketWechat"));
                    //二维码银联金额
                    insertObj.setQrCodeTicketUnionpay(qrCodeTicketMap.get("qrCodeTicketUnionpay"));
                    //二维码小计
                    insertObj.setQrCodeSubTotal(insertObj.getQrCodeTicketAlipay() + insertObj.getQrCodeTicketWechat() + insertObj.getQrCodeTicketUnionpay());

                    Map<String,Long> faceRecognitionTicketBankMap = this.baseMapper.getFaceRecognitionTicketBank(insertObj);
                    //人脸识别银行金额
                    insertObj.setFaceRecognitionTicketBank(faceRecognitionTicketBankMap.get("faceRecognitionTicketBank"));

                    //交通一卡通
                    insertObj.setAllOneTrafficCard(0L);

                    Map<String,Long> stationCompensationMap = this.baseMapper.getStationCompensation(insertObj);
                    //补车站票款短款
                    insertObj.setStationCompensation(stationCompensationMap.get("stationCompensation"));

                    //备用金解行
                    insertObj.setReleasePettyCash(0L);

                    //现金合计
                    Long totalCash = insertObj.getTvmOneTicketCash() + insertObj.getBomOneTicketCash() + insertObj.getPrefabricatedTicketAmount()
                            + insertObj.getEmergencyTicketAmount() + insertObj.getTicketCounting() + insertObj.getDailyTicketCash() + insertObj.getCommemorativeTicketCash()
                            + insertObj.getCatTicketCash() + insertObj.getStationCompensation();

                    //解行金额,等于现金合计
                    insertObj.setSettlementAmount(totalCash);
                    //现金缴款单
                    Map<String,Long> bankCashPaymentNoteMap = this.baseMapper.getBankCashPaymentNote(insertObj);

                    Long diff = bankCashPaymentNoteMap.get("bankCashPaymentNote") - insertObj.getSettlementAmount();

                    if (diff  >= 0) {
                        //车站票款现金长款
                        insertObj.setStationTicketLongCash(diff);
                        insertObj.setStationTicketShortCash(0L);
                    } else {
                        insertObj.setStationTicketLongCash(0L);
                        //车站票款现金短款
                        insertObj.setStationTicketShortCash(diff);
                    }

                    //收入小计
                    insertObj.setSubTota(insertObj.getTvmOneTicketCash() + insertObj.getTvmOneTicketAlipay() + insertObj.getTvmOneTicketWechat() + insertObj.getTvmOneTicketBank() + insertObj.getBomOneTicketCash() +
                            insertObj.getBomOneTicketAlipay() + insertObj.getBomOneTicketWechat() + insertObj.getPrefabricatedTicketAmount() + insertObj.getEmergencyTicketAmount() + insertObj.getTicketCounting() +
                            insertObj.getDailyTicketCash() + insertObj.getDailyTicketAlipay() + insertObj.getDailyTicketWechat() + insertObj.getCommemorativeTicketCash() + insertObj.getCommemorativeTicketAlipay() +
                            insertObj.getCommemorativeTicketWechat() + insertObj.getAppCommemorativeTicket()  + insertObj.getOnlineTicketSales() +
                            insertObj.getQrCodeTicketAlipay() + insertObj.getQrCodeTicketWechat() + insertObj.getQrCodeTicketUnionpay() + insertObj.getFaceRecognitionTicketBank() +
                            insertObj.getStationTicketLongCash()
                    );

                    insertObj.setConfirmStatus("0");
                    insertList.add(insertObj);

            } else {
                    SwCkStationDailyReportAdjust insertObj = new SwCkStationDailyReportAdjust();
                    insertObj.setTradeDate(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                    insertObj.setLineCode(lineCode);
                    insertObj.setStationCode(stationCode);

                    //假如已经存在数据则返回
                    if (this.count(Wrappers.query(insertObj)) > 0){
                        continue;
                    }

                    insertObj.setSettleBeginTime(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                    insertObj.setSettleEndTime(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));

                    insertObj.setDeptId(user.getDeptId());
                    insertObj.setCreatorId(user.getId());
                    insertObj.setCreatorName(user.getNikeName());

                    insertObj.setTvmOneTicketCash(0L);
                    insertObj.setTvmOneTicketAlipay(0L);
                    insertObj.setTvmOneTicketWechat(0L);
                    insertObj.setTvmOneTicketBank(0L);
                    insertObj.setTvmSubTotal(0L);
                    insertObj.setBomOneTicketCash(0L);
                    insertObj.setBomOneTicketAlipay(0L);
                    insertObj.setBomOneTicketWechat(0L);
                    insertObj.setBomSubTotal(0L);
                    insertObj.setPrefabricatedTicketAmount(0L);
                    insertObj.setEmergencyTicketAmount(0L);
                    insertObj.setTicketCounting(0L);
                    insertObj.setDailyTicketCash(0L);
                    insertObj.setDailyTicketAlipay(0L);
                    insertObj.setDailyTicketWechat(0L);
                    insertObj.setDailySubTotal(0L);
                    insertObj.setCommemorativeTicketCash(0L);
                    insertObj.setCommemorativeTicketAlipay(0L);
                    insertObj.setCommemorativeTicketWechat(0L);
                    insertObj.setCommemorativeTicketSubTotal(0L);
                    insertObj.setAppCommemorativeTicket(0L);
                    insertObj.setCatTicketCash(0L);
                    insertObj.setCatTicketAlipay(0L);
                    insertObj.setCatTicketWechat(0L);
                    insertObj.setCatTicketItvmCash(0L);
                    insertObj.setCatTicketItvmAlipay(0L);
                    insertObj.setCatTicketItvmWechat(0L);
                    insertObj.setCatTicketItvmBank(0L);
                    insertObj.setCatSubTotal(0L);
                    insertObj.setCatTicketPayCard(0L);
                    insertObj.setOnlineTicketSales(0L);
                    insertObj.setQrCodeTicketAlipay(0L);
                    insertObj.setQrCodeTicketWechat(0L);
                    insertObj.setQrCodeTicketUnionpay(0L);
                    insertObj.setQrCodeSubTotal(0L);
                    insertObj.setFaceRecognitionTicketBank(0L);
                    insertObj.setAllOneTrafficCard(0L);
                    insertObj.setStationCompensation(0L);
                    insertObj.setReleasePettyCash(0L);
                    insertObj.setSettlementAmount(0L);
                    insertObj.setStationTicketShortCash(0L);
                    insertObj.setStationTicketLongCash(0L);
                    insertObj.setSubTota(0L);
                    insertObj.setConfirmStatus("0");
                    insertList.add(insertObj);
                }

        }

    }

        boolean flag = false;
       if(!insertList.isEmpty()){
           flag = this.saveBatch(insertList);
       }
       if(flag){
           //插入或者更新按线路每日汇总值
           insertOrUpdateDaySum(stationObjList,listDate);
       }
        return flag;*/
		return true;
    }

	 /**
         * 插入或者更新按线路每日汇总值
         * @param
         * @return
         */
    private void insertOrUpdateDaySum(List<Map<String,String>> stationObjList, List<String> listDate) throws Exception {

        //线路和日期 Set
        Set<SwCkStationDailyReportQueryDTO> set = new HashSet<>();
        PigxUser user = SecurityUtils.getUser();
        for (Map<String,String> stationMap : stationObjList) {
            String lineCode = stationMap.get("LINE_CODE");
            for(String settleDate : listDate) {
                SwCkStationDailyReportQueryDTO dto = new SwCkStationDailyReportQueryDTO();
                dto.setLineCode(lineCode);
                dto.setTradeDate(settleDate);
                set.add(dto);
            }
        }

        //线路和日期Set循环
        for (SwCkStationDailyReportQueryDTO dto : set){
            //查询库表里原来的汇总值
            SwCkStationDailyReportAdjust condtion = new SwCkStationDailyReportAdjust();
            condtion.setTradeDate(LocalDate.parse(dto.getTradeDate(), DateTimeFormatter.ofPattern(DateUtils.DATE_FORMAT_10)));
            condtion.setLineCode(dto.getLineCode());
            condtion.setStationCode(sumStationCode);
            SwCkStationDailyReportAdjust dbSum =  this.getOne(Wrappers.query(condtion));

            //查询按线路和日期的列表
            List<SwCkStationDailyReportAdjust> list = this.baseMapper.listSwCkStationDailyReportAdjust(dto);
            //根据列表得到汇总值
            SwCkStationDailyReportAdjust swCkStationDailyReportAdjustSum = getSwCkStationDailyReportAdjustSum(list,null,null);

            //假如原来的汇总值已经存在则更新
            if (dbSum!= null){
                MyBeanUtils.copyProperties(swCkStationDailyReportAdjustSum,dbSum);
                this.updateById(dbSum);
            } else {//不存在则插入
                //拿一条数据做模板
                SwCkStationDailyReportAdjust insertObj = list.get(0);
                MyBeanUtils.copyProperties(swCkStationDailyReportAdjustSum,insertObj);
                insertObj.setId(null);

                insertObj.setSettleBeginTime(insertObj.getTradeDate());
                insertObj.setSettleEndTime(insertObj.getTradeDate());

                insertObj.setDeptId(user.getDeptId());
                insertObj.setCreatorId(user.getId());
                insertObj.setCreatorName(user.getNikeName());
                insertObj.setConfirmStatus("0");
                this.save(insertObj);
            }
        }

    }
	  //根据列表得到汇总值
    public SwCkStationDailyReportAdjust getSwCkStationDailyReportAdjustSum(List<SwCkStationDailyReportAdjust> list, String catTicketPayCard, String allOneTrafficCard){
        SwCkStationDailyReportAdjust swCkStationDailyReportAdjustSum = new SwCkStationDailyReportAdjust();

        swCkStationDailyReportAdjustSum.setTradeDate(list.get(0).getTradeDate());
        swCkStationDailyReportAdjustSum.setLineCode(list.get(0).getLineCode());
        swCkStationDailyReportAdjustSum.setStationCode(sumStationCode);

        Long tvmOneTicketCashSum = 0L;
        Long tvmOneTicketAlipaySum = 0L;
        Long tvmOneTicketWechatSum = 0L;
        Long tvmOneTicketBankSum = 0L;
        Long tvmSubTotalSum = 0L;
        Long bomOneTicketCashlSum = 0L;
		Long bomOnePosAmountSum = 0L;
        Long bomOneTicketAlipaySum = 0L;

        Long bomOneTicketWechatSum = 0L;
        Long bomSubTotalSum = 0L;
        Long prefabricatedTicketAmountSum = 0L;
		Long prefabricatedTicketPosAmountSum = 0L;
        Long emergencyTicketAmountSum = 0L;
        Long ticketCountingSum = 0L;
        
		Long dailyTicketCashSum = 0L;
		Long dailyTicketPosAmountSum = 0L;
        Long dailyTicketAlipaySum = 0L;

        Long dailyTicketWechatSum = 0L;
		Long dailyTicketCatSum = 0L;
        Long dailySubTotalSum = 0L;
       
		Long commemorativeTicketCashSum = 0L;
		Long commemorativeTicketPosAmountSum = 0L;
        Long commemorativeTicketAlipaySum = 0L;
        Long commemorativeTicketWechatSum = 0L;
        Long commemorativeTicketSubTotalSum = 0L;
        Long appCommemorativeTicketSum = 0L;

        Long catTicketCashSum = 0L;
		Long catTicketPosAmountSum = 0L;
        Long catTicketAlipaySum = 0L;
        Long catTicketWechatSum = 0L;
        Long catTicketItvmCashSum = 0L;
        Long catTicketItvmAlipaySum = 0L;
        Long catTicketItvmWechatSum = 0L;
        Long catTicketItvmBankSum = 0L;
        Long catSubTotalSum = 0L;

        Long onlineTicketSalesSum = 0L;
        Long qrCodeTicketAlipaySum = 0L;
        Long qrCodeTicketWechatSum = 0L;
        Long qrCodeTicketUnionpaySum = 0L;
        Long qrCodeTicketAppSum = 0L;
		Long qrCodeTicketWechatappDiscountSum = 0L;
		Long qrCodeTicketWechatappSum = 0L;
        Long qrCodeSubTotalSum = 0L;
        Long faceRecognitionTicketBankSum = 0L;

        Long qrConnectivityAlipaySum = 0L;
        Long qrConnectivityWechatSum = 0L;
        Long qrConnectivitySubTotalSum = 0L;

        Long stationTicketLongCashSum = 0L;
        Long stationTicketShortCashSum = 0L;
        Long stationCompensationSum = 0L;
        Long releasePettyCashSum = 0L;
        Long settlementAmountSum = 0L;
		Long subTotaPosSum = 0L;		
        BigDecimal subTotaSum = new BigDecimal("0");
        for (SwCkStationDailyReportAdjust swCkStationDailyReportAdjust : list) {
                tvmOneTicketCashSum = tvmOneTicketCashSum + swCkStationDailyReportAdjust.getTvmOneTicketCash();
                tvmOneTicketAlipaySum = tvmOneTicketAlipaySum + swCkStationDailyReportAdjust.getTvmOneTicketAlipay();
                tvmOneTicketWechatSum = tvmOneTicketWechatSum + swCkStationDailyReportAdjust.getTvmOneTicketWechat();
                tvmOneTicketBankSum = tvmOneTicketBankSum + swCkStationDailyReportAdjust.getTvmOneTicketBank();
                tvmSubTotalSum = tvmSubTotalSum + swCkStationDailyReportAdjust.getTvmSubTotal();
               
				bomOneTicketCashlSum = bomOneTicketCashlSum + swCkStationDailyReportAdjust.getBomOneTicketCash();
				bomOnePosAmountSum = bomOnePosAmountSum + swCkStationDailyReportAdjust.getBomOnePosAmount();
                bomOneTicketAlipaySum = bomOneTicketAlipaySum + swCkStationDailyReportAdjust.getBomOneTicketAlipay();

                bomOneTicketWechatSum = bomOneTicketWechatSum + swCkStationDailyReportAdjust.getBomOneTicketWechat();
                bomSubTotalSum = bomSubTotalSum + swCkStationDailyReportAdjust.getBomSubTotal();
                
				prefabricatedTicketAmountSum = prefabricatedTicketAmountSum + swCkStationDailyReportAdjust.getPrefabricatedTicketAmount();
				prefabricatedTicketPosAmountSum = prefabricatedTicketPosAmountSum + swCkStationDailyReportAdjust.getPrefabricatedTicketPosAmount();
               
				emergencyTicketAmountSum = emergencyTicketAmountSum + swCkStationDailyReportAdjust.getEmergencyTicketAmount();
                ticketCountingSum = ticketCountingSum + swCkStationDailyReportAdjust.getTicketCounting();
                
				dailyTicketCashSum = dailyTicketCashSum + swCkStationDailyReportAdjust.getDailyTicketCash();
				dailyTicketPosAmountSum = dailyTicketPosAmountSum + swCkStationDailyReportAdjust.getDailyTicketPosAmount();
                dailyTicketAlipaySum = dailyTicketAlipaySum + swCkStationDailyReportAdjust.getDailyTicketAlipay();

                dailyTicketWechatSum = dailyTicketWechatSum + swCkStationDailyReportAdjust.getDailyTicketWechat();
				dailyTicketCatSum = dailyTicketCatSum + swCkStationDailyReportAdjust.getDailyTicketCat();
                dailySubTotalSum = dailySubTotalSum + swCkStationDailyReportAdjust.getDailySubTotal();
               
				commemorativeTicketCashSum = commemorativeTicketCashSum + swCkStationDailyReportAdjust.getCommemorativeTicketCash();
				commemorativeTicketPosAmountSum = commemorativeTicketPosAmountSum + swCkStationDailyReportAdjust.getCommemorativeTicketCash();
                commemorativeTicketAlipaySum = commemorativeTicketAlipaySum + swCkStationDailyReportAdjust.getCommemorativeTicketAlipay();
                commemorativeTicketWechatSum = commemorativeTicketWechatSum + swCkStationDailyReportAdjust.getCommemorativeTicketWechat();
                commemorativeTicketSubTotalSum = commemorativeTicketSubTotalSum + swCkStationDailyReportAdjust.getCommemorativeTicketSubTotal();
                
				appCommemorativeTicketSum = appCommemorativeTicketSum + swCkStationDailyReportAdjust.getAppCommemorativeTicket();

                catTicketCashSum = catTicketCashSum + swCkStationDailyReportAdjust.getCatTicketCash();
				catTicketPosAmountSum = catTicketPosAmountSum + swCkStationDailyReportAdjust.getCatTicketPosAmount();
                catTicketAlipaySum = catTicketAlipaySum + swCkStationDailyReportAdjust.getCatTicketAlipay();
                catTicketWechatSum = catTicketWechatSum + swCkStationDailyReportAdjust.getCatTicketWechat();
                catTicketItvmCashSum = catTicketItvmCashSum + swCkStationDailyReportAdjust.getCatTicketItvmCash();
                catTicketItvmAlipaySum = catTicketItvmAlipaySum + swCkStationDailyReportAdjust.getCatTicketItvmAlipay();
                catTicketItvmWechatSum = catTicketItvmWechatSum + swCkStationDailyReportAdjust.getCatTicketItvmWechat();
                catTicketItvmBankSum = catTicketItvmBankSum + swCkStationDailyReportAdjust.getCatTicketItvmBank();
                catSubTotalSum = catSubTotalSum + swCkStationDailyReportAdjust.getCatSubTotal();

                onlineTicketSalesSum = onlineTicketSalesSum + swCkStationDailyReportAdjust.getOnlineTicketSales();
                qrCodeTicketAlipaySum = qrCodeTicketAlipaySum + swCkStationDailyReportAdjust.getQrCodeTicketAlipay();
                qrCodeTicketWechatSum = qrCodeTicketWechatSum + swCkStationDailyReportAdjust.getQrCodeTicketWechat();
                qrCodeTicketUnionpaySum = qrCodeTicketUnionpaySum + swCkStationDailyReportAdjust.getQrCodeTicketUnionpay();
                qrCodeTicketAppSum = qrCodeTicketAppSum + swCkStationDailyReportAdjust.getQrCodeTicketApp();
				qrCodeTicketWechatappDiscountSum = qrCodeTicketWechatappDiscountSum + swCkStationDailyReportAdjust.getQrCodeTicketWechatappDiscount();
				qrCodeTicketWechatappSum = qrCodeTicketWechatappSum + swCkStationDailyReportAdjust.getQrCodeTicketWechatapp();

                qrCodeSubTotalSum = qrCodeSubTotalSum + swCkStationDailyReportAdjust.getQrCodeSubTotal();
                faceRecognitionTicketBankSum = faceRecognitionTicketBankSum + swCkStationDailyReportAdjust.getFaceRecognitionTicketBank();

                qrConnectivityAlipaySum = qrConnectivityAlipaySum + swCkStationDailyReportAdjust.getQrConnectivityAlipay();
                qrConnectivityWechatSum = qrConnectivityWechatSum + swCkStationDailyReportAdjust.getQrConnectivityWechat();
                qrConnectivitySubTotalSum = qrConnectivitySubTotalSum + swCkStationDailyReportAdjust.getQrConnectivitySubTotal();

                stationTicketLongCashSum = stationTicketLongCashSum + swCkStationDailyReportAdjust.getStationTicketLongCash();
                stationTicketShortCashSum = stationTicketShortCashSum + swCkStationDailyReportAdjust.getStationTicketShortCash();
                stationCompensationSum = stationCompensationSum + swCkStationDailyReportAdjust.getStationCompensation();
                releasePettyCashSum = releasePettyCashSum + swCkStationDailyReportAdjust.getReleasePettyCash();
				subTotaPosSum = subTotaPosSum + swCkStationDailyReportAdjust.getSubTotaPos();
                settlementAmountSum = settlementAmountSum + swCkStationDailyReportAdjust.getSettlementAmount();
                subTotaSum = subTotaSum.add(swCkStationDailyReportAdjust.getSubTota());
            }
        swCkStationDailyReportAdjustSum.setTvmOneTicketCash(tvmOneTicketCashSum);
        swCkStationDailyReportAdjustSum.setTvmOneTicketAlipay(tvmOneTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setTvmOneTicketWechat(tvmOneTicketWechatSum);
        swCkStationDailyReportAdjustSum.setTvmOneTicketBank(tvmOneTicketBankSum);
        swCkStationDailyReportAdjustSum.setTvmSubTotal(tvmSubTotalSum);

        swCkStationDailyReportAdjustSum.setBomOneTicketCash(bomOneTicketCashlSum);
		swCkStationDailyReportAdjustSum.setBomOnePosAmount(bomOnePosAmountSum);
        swCkStationDailyReportAdjustSum.setBomOneTicketAlipay(bomOneTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setBomOneTicketWechat(bomOneTicketWechatSum);
        swCkStationDailyReportAdjustSum.setBomSubTotal(bomSubTotalSum);
        swCkStationDailyReportAdjustSum.setPrefabricatedTicketAmount(prefabricatedTicketAmountSum);
		swCkStationDailyReportAdjustSum.setPrefabricatedTicketPosAmount(prefabricatedTicketPosAmountSum);

        swCkStationDailyReportAdjustSum.setEmergencyTicketAmount(emergencyTicketAmountSum);
        swCkStationDailyReportAdjustSum.setTicketCounting(ticketCountingSum);
       
		swCkStationDailyReportAdjustSum.setDailyTicketCash(dailyTicketCashSum);
		swCkStationDailyReportAdjustSum.setDailyTicketPosAmount(dailyTicketPosAmountSum);
        swCkStationDailyReportAdjustSum.setDailyTicketAlipay(dailyTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setDailyTicketWechat(dailyTicketWechatSum);
		swCkStationDailyReportAdjustSum.setDailyTicketCat(dailyTicketCatSum);

        swCkStationDailyReportAdjustSum.setDailySubTotal(dailySubTotalSum);
        swCkStationDailyReportAdjustSum.setCommemorativeTicketCash(commemorativeTicketCashSum);
		swCkStationDailyReportAdjustSum.setCommemorativeTicketPosAmount(commemorativeTicketPosAmountSum);
        swCkStationDailyReportAdjustSum.setCommemorativeTicketAlipay(commemorativeTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setCommemorativeTicketWechat(commemorativeTicketWechatSum);
        swCkStationDailyReportAdjustSum.setCommemorativeTicketSubTotal(commemorativeTicketSubTotalSum);

        swCkStationDailyReportAdjustSum.setAppCommemorativeTicket(appCommemorativeTicketSum);
        swCkStationDailyReportAdjustSum.setCatTicketCash(catTicketCashSum);
		swCkStationDailyReportAdjustSum.setCatTicketPosAmount(catTicketPosAmountSum);
        swCkStationDailyReportAdjustSum.setCatTicketAlipay(catTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setCatTicketWechat(catTicketWechatSum);
        swCkStationDailyReportAdjustSum.setCatTicketItvmCash(catTicketItvmCashSum);

        swCkStationDailyReportAdjustSum.setCatTicketItvmAlipay(catTicketItvmAlipaySum);
        swCkStationDailyReportAdjustSum.setCatTicketItvmWechat(catTicketItvmWechatSum);
        swCkStationDailyReportAdjustSum.setCatTicketItvmBank(catTicketItvmBankSum);
        swCkStationDailyReportAdjustSum.setCatSubTotal(catSubTotalSum);

        //长安通刷卡消费
//        Map<String,BigDecimal> catTicketPayCardSumMap = this.baseMapper.getCatTicketPayCardSum(swCkStationDailyReportAdjustSum);
//        swCkStationDailyReportAdjustSum.setCatTicketPayCard(catTicketPayCardSumMap.get("catTicketPayCardSum"));
        swCkStationDailyReportAdjustSum.setCatTicketPayCard(new BigDecimal(catTicketPayCard));

        swCkStationDailyReportAdjustSum.setOnlineTicketSales(onlineTicketSalesSum);
        swCkStationDailyReportAdjustSum.setQrCodeTicketAlipay(qrCodeTicketAlipaySum);
        swCkStationDailyReportAdjustSum.setQrCodeTicketWechat(qrCodeTicketWechatSum);
        swCkStationDailyReportAdjustSum.setQrCodeTicketUnionpay(qrCodeTicketUnionpaySum);
        swCkStationDailyReportAdjustSum.setQrCodeTicketApp(qrCodeTicketAppSum);
		swCkStationDailyReportAdjustSum.setQrCodeTicketWechatappDiscount(qrCodeTicketWechatappDiscountSum);
		swCkStationDailyReportAdjustSum.setQrCodeTicketWechatapp(qrCodeTicketWechatappSum);
        swCkStationDailyReportAdjustSum.setQrCodeSubTotal(qrCodeSubTotalSum);

        swCkStationDailyReportAdjustSum.setFaceRecognitionTicketBank(faceRecognitionTicketBankSum);

        //互联互通
        swCkStationDailyReportAdjustSum.setQrConnectivityAlipay(qrConnectivityAlipaySum);
        swCkStationDailyReportAdjustSum.setQrConnectivityWechat(qrConnectivityWechatSum);
        swCkStationDailyReportAdjustSum.setQrConnectivitySubTotal(qrConnectivitySubTotalSum);

        //交通一卡通
//        Map<String,BigDecimal> allOneTrafficCardSumMap = this.baseMapper.getAllOneTrafficCardSum(swCkStationDailyReportAdjustSum);
//        swCkStationDailyReportAdjustSum.setAllOneTrafficCard(allOneTrafficCardSumMap.get("allOneTrafficCardSum"));
        swCkStationDailyReportAdjustSum.setAllOneTrafficCard(new BigDecimal(allOneTrafficCard));

        swCkStationDailyReportAdjustSum.setStationTicketLongCash(stationTicketLongCashSum);
        swCkStationDailyReportAdjustSum.setStationTicketShortCash(stationTicketShortCashSum);
        swCkStationDailyReportAdjustSum.setStationCompensation(stationCompensationSum);

        swCkStationDailyReportAdjustSum.setReleasePettyCash(releasePettyCashSum);
		swCkStationDailyReportAdjustSum.setSubTotaPos(subTotaPosSum);
        swCkStationDailyReportAdjustSum.setSettlementAmount(settlementAmountSum);
        swCkStationDailyReportAdjustSum.setSubTota(subTotaSum.add(new BigDecimal(allOneTrafficCard)).add(new BigDecimal(catTicketPayCard)));

        return swCkStationDailyReportAdjustSum;
    }
   
	private boolean parseDate(String string) {
        boolean convertSuccess = true;
        if (string == null) {
            return false;
        }

        try {
            DateUtils.parseDate(string, "yyyy-MM-dd");
        } catch (ParseException e) {
            convertSuccess = false;
        }
        return convertSuccess;
    }
	private String getLineCode (List<Map<String,String>> lineMap,String lineName) {
        for (Map<String,String> map : lineMap){
            if(lineName.equals(map.get("NAME"))){
                return map.get("CODE");
            }
        }
        return "";
    }

    private String getStationCode (List<Map<String,String>> stationMap,String stationName,String lineCode) {
        for (Map<String,String> map : stationMap){
            if(stationName.equals(map.get("NAME")) && lineCode.equals(map.get("VLINE_CODE"))){
                return map.get("CODE");
            }
        }
        return "";
    }
	private Long getLongValue(String value){
        if(value == null || StringUtils.isEmpty(value)){
            return 0l;
        }
        return new BigDecimal(value).multiply(new BigDecimal("100")).longValue();
    }
  private Long getImportLongValue(String value){
	   if(value == null || StringUtils.isEmpty(value)){
            return 0l;
        }
		BigDecimal money = new BigDecimal(value);
		BigDecimal num = new BigDecimal("100");
        money = money.multiply(num).setScale(2, BigDecimal.ROUND_HALF_UP);       
		return money.longValue();
        //return new BigDecimal(value).multiply(new BigDecimal("100")).longValue();
    }
   private BigDecimal getDecimalValue(String value){
       if(value == null || StringUtils.isEmpty(value)){
            return new BigDecimal("0");
        }
        return new BigDecimal(value).multiply(new BigDecimal("100"));
    }
}
